package com.googlecode.player.view.specialmaterials
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.papervision3d.materials.MovieMaterial;

	public class TextMaterial extends MovieMaterial
	{
		protected var _textMC:MovieClip = new MovieClip();
		
		protected var _bg:MovieClip = new MovieClip();

		protected var _textField:TextField = new TextField();
		
		protected var _textFormat:TextFormat = new TextFormat( "Arial" );
			
		public function TextMaterial(text:String="Default", font:String="Arial", fontSize:uint=36, fontColor:uint=0, width:uint=500, height:uint=500, backgroundColor:uint=0xFFFFFF, backgroundAlpha:Number=1)
		{		
			_textField.wordWrap = true;
			
			_textField.width = width;
			
			_textField.height = height;
			
			_textField.multiline = true;
			
			_textField.text = text;
			
			_textField.autoSize = TextFieldAutoSize.NONE;
			
			_textField.scrollRect = new Rectangle(0, 0, width, height);
			
			
			_textFormat.font = font;			
			
			_textFormat.size = fontSize;
			
			_textFormat.color = fontColor;
			
			_textField.setTextFormat( _textFormat );
			
			
			_bg.graphics.beginFill( backgroundColor, backgroundAlpha );
			
			_bg.graphics.drawRect( 0, 0, width, height );
			
			_bg.graphics.endFill();
			
			_textMC.addChild( _bg );
					
			_textMC.graphics.beginFill( 0, 0 );
			
			_textMC.graphics.drawRect( 0, 0, width, height );
			
			_textMC.graphics.endFill();
			
			_textMC.addChild( _textField );
			
			//var txtMaterial:MovieMaterial = new MovieMaterial(textMC, true, false, true);
			
			this.smooth = true;
			
			this.tiled = true;
			
			super(_textMC, true, false, true);
		}
		
	}
}